﻿/*
 * beautyStyle JavaScript Plus v1.0.0
 * http://Julying.com/
 *
 * Copyright (c) 2009 Wang
 * Dual licensed under the MIT and GPL licenses.
 * http://Julying.com/
 *
 * Date: 2009-12-03 17:34:21
 * Revision: 2		
*/
(function($){
	var IE6 = false;
	if(  $.browser.msie && $.browser.version.slice(0,1) == 6 ) IE6 = true;
	if(typeof(beautyStylePath) == 'undefined') beautyStylePath  = 'jslab/beautyStyle/';
	$.fn.beautyStyle = function(options){
		this.each(function(){		
			var opts = $.extend({}, $.fn.beautyStyle.defaults, options);
			var BG_PNG = beautyStylePath +'images/'+ opts.styleCSS +'.png';
			var BG = 'background-image:url('+ BG_PNG +');';
			var div_BG ='' ;
			var filter ="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='noscale' ,src='"+BG_PNG+"');";	
			x_span_filter = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true', sizingMethod='scale' ,src='"+BG_PNG+"');";
var C5_BG = "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src='"+ beautyStylePath+"images/"+opts.styleBG+"');";
			if(IE6){
				 BG = filter;
				 //opts.padding -= 5;
			}else{
				div_BG = BG ; BG = '';
				x_span_filter = '';
				C5_BG = '';
			};		
			var tableHTML = 
'<div class="openWin" type="'+ opts.type +'" style="margin:'+ opts.margin +';">'+
	'<table cellspacing="0" cellpadding="0" class="bP" style="width:'+ opts.width +';" align="'+opts.align+'">'+
	'<tr><td class="C C1"><div style="'+div_BG+'"><span style="'+BG+'"></span></div></td><td class="C C2"><div style="'+div_BG+'"><span style="'+x_span_filter+'"></span></div></td>'+
	'<td class="C C3"><div style="'+div_BG+'"><span style="'+BG+'"></span></div></td></tr>'+
	'<tr><td class="C C4"><div style="'+div_BG+'"><span style="'+BG+'"></span></div></td>'+
		'<td class="C5" style="'+ C5_BG+' ;background:url('+ beautyStylePath +'images/'+ opts.styleBG +'); _background:none; "><p class="C5P" style="padding:'+ (opts.padding) +'px;"></p></td>'+
	'<td class="C C6"><div style="'+div_BG+'"><span style="'+BG+'"></span></div></td></tr><tr><td class="C C7"><div style="'+div_BG+'"><span style="'+BG+'"></span></div></td>'+
	'<td class="C C8"><div style="'+div_BG+'"><span style="'+x_span_filter+'"></span></div></td><td class="C C9"><div style="'+div_BG+'"><span style="'+BG+'"></span></div></td></tr></table>'+
'</div>';
			var $this_obj = $(this).clone();
			$(this).after( tableHTML ).hide();	
			var $openWin = $(this).next('.openWin');
			$openWin.find('table p.C5P:first').append($this_obj)
			var docHeight = $openWin.find('.C5:first').height();
			$openWin.find('table tr td.C4:first,table tr td.C6:last').height( docHeight );
			setTimeout( opts.complete ,30);
		});
		if(!IE6) $('div.openWin .C span').hide();
		setTimeout(function(){ $.beautyStyleReSize(); },500);
	};
	$.beautyStyleReSize = function(){
		$('div.openWin').each(function(){
			if( $(this).attr('type') == 'img')
				var docHeight = $(this).find('.C5P').height();
			else
				var docHeight = $(this).find('.C5:first').height();
			$(this).find('.C4:first,.C6:last').height( docHeight );
		});
	};
	$.fn.beautyStyle.defaults = {
		styleCSS : 'drop-shadow' ,
		padding : 0 ,
		margin: 0,
		width : '' ,
		type:'',
		align:'',
		styleBG :'trsBg.png',
		complete:function(fn){}
	};
})(jQuery);